package com.alibaba.seckill.controller;


import com.alibaba.seckill.mapper.OrderMapper;
import com.alibaba.seckill.mapper.SeckillOrderMapper;
import com.alibaba.seckill.pojo.Order;
import com.alibaba.seckill.pojo.SeckillOrder;
import com.alibaba.seckill.pojo.User;
import com.alibaba.seckill.service.IOrderService;
import com.alibaba.seckill.vo.OrderDetailVo;
import com.alibaba.seckill.vo.RespBean;
import com.alibaba.seckill.vo.RespBeanEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 前端控制器
 * </p>
 * @author 曹帅
 * @since 2021-11-18
 */
@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private IOrderService orderService;
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private SeckillOrderMapper seckillOrderMapper;

    /**
     * 订单详情
     * @param user
     * @param orderId
     * @return
     */
    @RequestMapping("/detail")
    @ResponseBody
    public RespBean detail(User user, Long orderId) {
        if (null == user) {
            return RespBean.error(RespBeanEnum.SESSION_ERROR);
        }
        OrderDetailVo detail = orderService.detail(orderId);
        return RespBean.success(detail);
    }

    @RequestMapping("/test")
    @ResponseBody
    public void detail() {
        for (int i = 0; i < 5000; i++) {
            SeckillOrder seckillOrder = new SeckillOrder();
            seckillOrder.setGoodsId(3L);
            seckillOrderMapper.insert(seckillOrder);
        }

    }
}